package com.kolaxy.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * <p>todo</p>
 *
 * @author zhourunjin
 * @date 2020/6/10 12:36
 */
public class NioClient {

    public static void main(String[] args) throws Exception {
        SocketChannel channel = SocketChannel.open();
        channel.configureBlocking(false);
        InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 9999);
        channel.connect(inetSocketAddress);
        if (!channel.connect(inetSocketAddress)) {
            while (!channel.finishConnect()) {
                System.out.println("connceted!");
            }
        }

        ByteBuffer buffer = ByteBuffer.wrap("hello world!".getBytes());

        channel.write(buffer);

        Thread.sleep(19990);
        System.in.read();
    }
}
